#ifndef _GRAPHICS_MATERIAL_ATLAS_H
#define _GRAPHICS_MATERIAL_ATLAS_H

#include <vector>
#include "hacked_vector"
#include <Ogre.h>
#include "DwarfFort/InternalStructures.h"


namespace DwarfFort
{
	struct Matgloss;
};


namespace Graphics
{
	
	struct MaterialDef
	{
		std::string name;
		Ogre::TexturePtr mSource;
		float u,v,w,h;
		unsigned int useCount;
	};
	
	class MaterialAtlas
	{
		std::vector<MaterialDef *> mTextures;
		std::hacked_vector<DwarfFort::Matgloss*> &mDefinitions; 
		Ogre::TexturePtr mAtlas,mBlendMap;
		std::string mTextureListFile;
		Ogre::MaterialPtr mBaseMaterial,mBlendMaterial;
		
	public:
		
		MaterialAtlas(std::hacked_vector<DwarfFort::Matgloss*> &definitions,std::string textureList);
		~MaterialAtlas(void);
		void build();
		void loadDefinitions();
		Ogre::MaterialPtr getBaseMaterial() {return mBaseMaterial;}
		Ogre::MaterialPtr getBlendMaterial() {return mBlendMaterial;}
		size_t getDefaultMaterialIndex() {return mTextures.size()-1;}
		MaterialDef * getMaterialDef(size_t index) {return mTextures.at(index);}
		WORD getMaterialIndexByName(std::string &name);
		MaterialDef * getMaterialDefByName(std::string &name);
		const char *getMaterialName(size_t index) {return mDefinitions.at(index)->mCapsname.c_str();} 
		void generateBlendMap();

		MaterialDef * getOrCreateMaterialDef(size_t index);


	}; // class MaterialAtlas





}; // namespace Graphics
#endif